package s2.interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpSession;

/**
 * Created by IFT8
 * on 2015/7/18.
 */
public class PermInterceptor implements Interceptor {
    @Override
    public void destroy() {
    }

    @Override
    public void init() {
    }

    @Override
    public String intercept(ActionInvocation invocation) throws Exception {
        HttpSession session= ServletActionContext.getRequest().getSession();
        Object user = session.getAttribute("user");
        if (user == null) {
            return  "login";
        }
        return invocation.invoke();//调用Action的方法 (放行)
    }
}
